
/**
\file
Definition of the pass base class.
\author Sean Tromans
*/

#ifndef	RAINBOW_VIEWPORT_PASS_HPP
#define	RAINBOW_VIEWPORT_PASS_HPP

#include <rainbow/viewport/pass/pass_fwd.hpp>
#include <rainbow/draw_information/draw_information.hpp>
#include <rainbow/viewport/pass/decorated_draw_information/decorated_draw_information.hpp>
#include <sun/lua/lua_fwd.hpp>
#include <needs_more_ninja/interface.hpp>
#include <boost/function.hpp>
#include <set>

namespace rainbow
{

	/**
	Base pass class.
	Defines a single pass within a viewport.
	\author Sean Tromans
	*/
	class pass : public nmn::interface_
	{
		//
		//	Public Member Types
		//
		public:

		//
		//	Public Member Functions
		//
		public:

			/**
			Adds a draw information to this pass to drawn later.
			@param command The draw information to enqueue.
			\author Sean Tromans
			*/
			void enqueue( draw_information const & command );

			/**
			Informs the pass that all dependencies have been met and it is now time to draw.
			@param step_fraction How far between logic updates this frame is.
			\author Sean Tromans
			*/
			virtual void draw( float step_fraction ) = 0;

			/**
			Comparison callback to sort draw_commands.
			/note
				Default implementation uses rainbow::pass::default_ordering.
			@param a The first decorated_draw_information to compare.
			@param b The second decorated_draw_information to compare.
			@return true if \c a should preceed \c b. false otherwise.
			\author Sean Tromans
			*/
			virtual bool compare( decorated_draw_information const & a, decorated_draw_information const & b ) const;

		//
		//	Protected Member Functions
		//
		protected:

			/**
			Default constructor
			\author Sean Tromans
			*/
			pass( );

		//
		//	Private Member Types
		//
		private:

			/** Comparrison function to order draw_commands in the render queue. */
			typedef boost::function< bool ( decorated_draw_information const & a, decorated_draw_information const & b ) > draw_information_compare_t;

			/** Queue of draw_commands to be processed during the draw. */
			typedef std::multiset< decorated_draw_information, draw_information_compare_t > render_queue_t;

		//
		//	Private Member Variables
		//
		private:

			render_queue_t m_render_queue;	///< The list of draw_commands this pass will process during it's draw call.

		//
		//	Static Member Functions
		//
		public:

			/**
			Exposes the pass to lua.
			@param L The Lua State being initialised.
			\author Sean Tromans.
			*/
			static void lua_interface( lua_State * L );
	};

};

#endif	//RAINBOW_VIEWPORT_PASS_HPP
